//
//  LeftGroupCustomCollectionViewCell.m
//  Delicious2
//
//  Created by dllo on 16/1/9.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "LeftGroupCustomCollectionViewCell.h"

@implementation LeftGroupCustomCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageV = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.imageV.userInteractionEnabled = YES;
        
        self.labelTitle = [[UILabel alloc] initWithFrame:CGRectZero];
        self.labelTitle.font = [UIFont boldSystemFontOfSize:15];
        self.labelTitle.textAlignment = NSTextAlignmentCenter;
        
        [self addSubview:self.imageV];
        [self addSubview:self.labelTitle];

    }
    return self;
}

- (void)setGroupModel:(LeftGroupModel *)groupModel {
    if (_groupModel != groupModel) {
        _groupModel = groupModel;
    }
    if (groupModel.image_url != NULL) {
        [self.imageV sd_setImageWithURL:[NSURL URLWithString:groupModel.image_url]];
    } else {
         self.labelTitle.frame = CGRectMake(15, self.frame.size.height / 2, self.imageV.frame.size.width + 20, 30);
        self.labelTitle.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:250/255.0 alpha:1.0];
    }
    self.labelTitle.text = groupModel.name;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super layoutSubviews];
    
    self.imageV.frame = CGRectMake(25 , 10, self.frame.size.width - 60, self.frame.size.height - 50);
    self.labelTitle.frame = CGRectMake(15, self.frame.size.height - 40, self.imageV.frame.size.width + 20, 30);
}

@end
